refactor: replace deprecated Result.Requeue in controller reconcilers - #1348
refactor: replace deprecated Result.Requeue in controller reconcilers#1348christian-heusel wants to merge 2 commits into
Conversation
|
[APPROVALNOTIFIER] This PR is NOT APPROVED This pull-request has been approved by: The full list of commands accepted by this bot can be found here. DetailsNeeds approval from an approver in each of these files:Approvers can indicate their approval by writing |
|
/cc @siyuanfoundation @thesuperzapper |
|
I think for |
`controller-runtime` deprecates `reconcile.Result.Requeue` in favor of `RequeueAfter` / returning an error. The dependency bump in kubeflow#1306 moves the controller to `controller-runtime v0.24.1`, where `staticcheck` flags **every** `Result{Requeue: true}` usage as `SA1019`: This setting is deprecated as it causes confusion and there is no good reason to use it. When waiting for an external event to happen, either the duration until it is supposed to happen or an appropriate poll interval should be used, rather than an interval emitted by a ratelimiter whose purpose it is to control retry on error. Deprecated: Use `RequeueAfter` instead. Therefore this change replaces every usage in the controller reconcilers: - Conflict-retry sites now return the conflict error so the workqueue rate-limiter handles retry-on-error (its documented purpose), which preserves the same rate-limited backoff that `Requeue: true` provided. - Stale-cache sites (`ServiceAccount` not yet in the cache) rely on the `Owns(ServiceAccount)` watch to requeue, matching the existing comments. - `mergeReconcileResult` drops its `.Requeue` handling and now merges purely on `RequeueAfter` its unit test is updated accordingly. Tradeoff for discussion: conflict errors are now surfaced by controller-runtime at error level rather than staying quiet at `V(2)`. Assisted-by: Claude Opus 4.8 <noreply@anthropic.com> Signed-off-by: Christian Heusel <christian@heusel.eu>
Addresses review feedback on the stale-cache handling: relying on the `Owns(ServiceAccount)` watch to requeue is not guaranteed, because a ServiceAccount with the deterministic name that is owned by another controller will never be mapped back to this Workspace. Requeue with a small fixed `RequeueAfter` instead: a stale cache is common and is not write contention, so no exponential backoff is needed. Assisted-by: Qwen3.8-27B Signed-off-by: Christian Heusel <christian@heusel.eu>
c05d80e to
58a5323
Compare
controller-runtimedeprecatesreconcile.Result.Requeuein favor ofRequeueAfter/ returning an error. The dependency bump in #1306 movesthe controller to
controller-runtime v0.24.1, wherestaticcheckflags every
Result{Requeue: true}usage asSA1019:Approach
The reconciler used
Requeue: truein two distinct situations, handled differently:IsConflict(err)retry after an updatereturn Result{Requeue: true}, nilreturn Result{}, errreturn Result{Requeue: true}, nilreturn Result{}, nilOwns(&ServiceAccount{}), so the owned-object watch will requeue us — the existing code comments already say so. No explicit requeue needed.mergeReconcileResult()no longer inspects the deprecated.Requeuefield and merges purely onRequeueAfter; its unit test was updated to match.Options considered
Requeue: trueRequeueAfter: <small const>nil)//nolint:staticcheckDiscussion points
V(2)and returned asnil) now surface via controller-runtime's"Reconciler error"at error level (and bump the error metric). Is that acceptable, or do we prefer option B (RequeueAfter) to keep conflicts quiet at the cost of changing the retry cadence?Owns(&ServiceAccount{})watch to requeue acceptable, or should we rather keep an explicit shortRequeueAfteras a safety net?k8s.io/apimachinery/pkg/util/httpstream→k8s.io/streaming/pkg/httpstream(the otherSA1019the bump surfaces), or keep that as a separate PR?related: #1306